import {defineStore} from 'pinia'
import {routes} from "../router"

// 登录信息
import {loginGather, userGather, userGetters} from './modules/user.js'
// 音乐数据
import {dataMusic, playMusicGather, getterMusic} from './modules/playMusic.js'
// 歌曲数据
import { musicListState, musicListAction, musicListGetter } from './modules/getMusicList.js'
// 分享
import { shareAction, shareState, shareGetters } from "./modules/share.js";
// 评论
import { reviewState, reviewGetters, reviewActions } from "./modules/review.js";
// 电台
import { radioState, radioActions, radioGetters } from "./modules/radio.js";
// 歌手信息
import { songState, songGetters, songActions } from  './modules/song.js'

export const useStore = defineStore('id', {
  state: () => {
    return {
      routes: routes,
      isFlag: true, // 监听视口大小
      ...userGather,
      ...dataMusic,
      ...musicListState,
      ...shareState,
      ...reviewState,
      ...radioState,
      ...songState,
      theme: {
        HoverBgColor: "rgb(240, 238, 238)", // hover背景颜色
        bgColor: "rgba(100, 123, 226, 0.64)",// 一级背景
        hoverTextColor: "rgb(46, 46, 48)", // hover字体颜色
        secondaryBgColor: "rgba(109, 71, 255, 0.38)",  // 二级背景颜色
        textColor: "rgb(255,255,255)", // 字体颜色
        titleTextColor: "rgb(170, 109, 235)", // 默认字体颜色
      },
      // 由于音乐播放器在播放时有时候请求会403，
      // 所以需要重新请求，当前播放的音乐如果重新请求之后还是不能播放就切换到下一首并在把这个值重置为FALSE
      limitRefresh: false,
      loginPopup: false, // 点击登录弹窗
      toggle: true, // 移动端监听是否通过二维码登录
      popupExpand: false, // 移动端显示层是否展开
      isShowMobileSearch: true, // 是否展示移动端搜索框通过isFlag和这个决定
      addPlaylistPopup: false, // 添加歌曲到自己的歌单弹窗
      newSongListPopup: false, // 新建歌单弹窗
    }
  },
  // 持久化存储
  persist: [
    // 存储播放歌曲的下标
    {
      key: 'songUrlIndex',
      storage: localStorage,
      paths: ['songUrlIndex']
    },
    // 存储歌单信息
    {
      key: 'privilegesTracks',
      storage: localStorage,
      paths: ['privilegesTracks']
    },
    // 存储当前歌曲播放时间
    {
      key: 'currentTime',
      storage: sessionStorage,
      paths: ['audioOptions.currentTime']
    },
    // 持久化存储theme
    {
      key: 'theme',
      storage: localStorage,
      paths: [
        'theme.HoverBgColor',
        'theme.bgColor',
        'theme.hoverTextColor',
        'theme.secondaryBgColor',
        'theme.textColor',
        'theme.titleTextColor'
      ]
    }
  ],
  // 计算属性
  getters: {
    ...getterMusic,
    ...userGetters,
    ...musicListGetter,
    ...shareGetters,
    ...reviewGetters,
    ...radioGetters,
    ...songGetters
  },
  // 相当于 methods
  actions: {
    ...loginGather,
    ...playMusicGather,
    ...musicListAction,
    ...shareAction,
    ...reviewActions,
    ...radioActions,
    ...songActions
  }
})
